<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/30
 * Time: 23:44
 */

class Finance extends Admin_Controller
{

    public function __construct()
    {
        parent::__construct();
        $this->load->model('Finance_model','finance_model');
    }

    public function index()
    {
        $this->load->view('admin/finance/list.html');
    }

    public function getList()
    {
        $info = $this->finance_model->getAll();
        if($info){
            show200_admin($info['data'],$info['count']);
        }else{
            show400_admin();
        }
    }

//  审核
    public function check(){
        $adminId = $this->session->userdata('adminId');
        $id = $this->input->post('id', TRUE);
        if(!$id) {
            show400('未获取到数据');
        }
        $row = $this->finance_model->getOne($id);
        if($row['status'] != 1) {
            show400('该记录不能修改');
        }
        $info = $this->finance_model->check($id, $adminId);
        if($info){
            show200('通过成功');
        }else{
            show400('通过失败');
        }
    }

    public function add()
    {
        $this->load->view('admin/finance/add.html');
    }

    public function addFinance()
    {
        $adminId = $this->session->userdata('adminId');
        $data=$this->input->post();
        if($data['password']!=$data['password_reapeat']){
            show300('两次密码输入不正确');
        }
        $info['phone']=$data['phone'];
        $info['trade_password']=md5($data['password']);
        $info['account']=$data['account'];
        $info['company_id']= $adminId;
        $info['user_name']=$data['user_name'];
        $info['status']=0;
        $info['type']=1;
        $info['create_time']=time();
        $row = $this->finance_model->getOne($adminId);
        if($row) {
            show400('已有账号');
        }
        $res=$this->finance_model->add($info);
        if($res){
            show200('添加成功');
        }else{
            show400('添加失败');
        }
    }

    public function checkno(){
        $adminId = $this->session->userdata('adminId');
        $id = $this->input->post('id', TRUE);
        if(!$id) {
            show400('未获取到数据');
        }
        $row = $this->finance_model->getOne($id);
        if($row['status'] != 1) {
            show400('该记录不能修改');
        }
        $info = $this->finance_model->checkno($id, $adminId);
        if($info){
            show200('拒绝成功');
        }else{
            show400('拒绝失败');
        }
    }
}